package com.leapp.sk.viewdelegate.adapter.task

import android.content.Context
import android.content.Intent
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.TextView
import com.example.mvp.delegate.BaseAdapterDelegate
import com.leapp.sk.R
import com.leapp.sk.bean.ParentingTaskEntity
import com.leapp.sk.ui.activity.task.TaskDetialActivity
import com.leapp.sk.ui.activity.task.TaskRequireActivity

/**
 * 亲子作业适配器视图托管类
 * @author  chaohaipeng  on 2018/8/3.
 */
class ParentingTaskAdapterDelegate: BaseAdapterDelegate(){
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_parenting_task
    }

    /**
     * 初始化数据
     */
    fun initData(context: Context, data: ParentingTaskEntity){
        val tv_apt_check_detial = getView<TextView>(R.id.tv_apt_check_detial)
        val tv_apt_complete = getView<TextView>(R.id.tv_apt_complete)
        val tv_apt_uncomplete = getView<TextView>(R.id.tv_apt_uncomplete)
        if (data.type==1){
            tv_apt_uncomplete.visibility=View.GONE
            tv_apt_complete.visibility=View.VISIBLE
            tv_apt_check_detial.setTextColor(ContextCompat.getColor(context,R.color.color_A3A5A8))
        }else{
            tv_apt_uncomplete.visibility=View.VISIBLE
            tv_apt_complete.visibility=View.GONE
            tv_apt_check_detial.setTextColor(ContextCompat.getColor(context,R.color.color_FF4447))
        }

        initEvent(context,data)

    }

    /**
     * 初始化事件
     */
    private  fun initEvent(context: Context,data: ParentingTaskEntity){
        val tv_apt_check_detial = getView<TextView>(R.id.tv_apt_check_detial)
        tv_apt_check_detial.setOnClickListener(View.OnClickListener {
            if (data.type==1) {
                val intent = Intent(context, TaskDetialActivity::class.java)
                context.startActivity(intent)
            }else{
                val intent = Intent(context, TaskRequireActivity::class.java)
                context.startActivity(intent)
            }
        })
    }
}